﻿$(document).ready(main);

function main() {

}

function raiseError(msg) {
    this.errorList[this.errorList.length] = msg;
}

function numErrors() {
    return this.errorList.length;
}

function formValidator() {
    this.errorList = new Array;

    this.isEmpty = isEmpty;
    this.isNumber = isNumber;
    this.isAlphabetic = isAlphabetic;
    this.isAlphaNumeric = isAlphaNumeric;
    this.isWithinRange = isWithinRange;
    this.isEmailAddress = isEmailAddress;
    this.isCheckedRadioButton = isCheckedRadioButton;
    this.isSelectedSelect = isSelectedSelect
    this.raiseError = raiseError;
    this.numErrors = numErrors; 
    this.displayErrors = displayErrors; 
}

function displayErrors() {
    for (x = 0; x < this.errorList.length; x++) {
        //alert("Error: " + this.errorList[x]);
    }
}

function isEmpty(val) {
    if (val.match(/^s+$/) || val == "") {
        return true;
    }
    else {
        return false;
    }
}


function isNumber(val) {
    if (val.match(/^[0-9]+$/)) {
        return true;
    }
    else {
        return false;
    }
}

function isAlphabetic(val) {
    if (val.match(/^[a-zA-ZáéíóúÁÉÍÓÚ ]+$/)) {
        return true;
    }
    else {
        return false;
    }
}

function isAlphaNumeric(val) {
    if (val.match(/^[a-zA-Z0-9-áéíóúÁÉÍÓÚ. ]+$/)) {
        return true;
    }
    else {
        return false;
    }
}

function isWithinRange(val, min, max) {
    if (val >= min && val <= max) {
        return true;
    }
    else {
        return false;
    }
}

function isEmailAddress(val) {
    if (val.match(/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/)) {
        return true;
    }
    else {
        return false;
    }
}

function isCheckedRadioButton(obj) {
    if (obj.is(":checked")) {
        return true;
    }
    else {
        return false;
    }
}

function isSelectedSelect(obj) {
    if (obj.selectedIndex > 0) {
        return true;
    }
    else {
        return false;
    }
}